//
//  ViewController.swift
//  SwiftTools
//
//  Created by hulinhu on 2017/11/22.
//  Copyright © 2017年 hulinhu. All rights reserved.
//

import UIKit
import YYModel

class ViewController: UIViewController {
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let sLabel = HLControl.createLabelWithFrame(frame: CGRect(x:10,y:80,width:100,height:100), text: "这是一个标签", textAlignment: .center, fontSize: 15, textColor: UIColor.white , bgColor: UIColor.red, cornerRadius: 10) {
            print("  点击了 ")
            

        }
        self.view .addSubview(sLabel)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
      netRequest()
        
    }
    
}

extension ViewController {
    
    func netRequest() {
        let url : String = "http://capi.douyucdn.cn/api/v1/getVerticalRoom"
        HLNetWorking.shareInstance.requestNetWork(netWorkType: .NetWorkTypeGET, requqestUrl: url, parameters:nil ) { (response) in
            //            print(response)
            //1.将result转成字典类型
            guard let  resultDic = response as? [String:NSObject] else{return}
            print(resultDic)
            
            let Infor  = ClassRoomData.yy_model(withJSON: resultDic)
            let dataArray = Infor?.data
//            print(dataArray!)
            
            let item : ClassRoomItem = (Infor?.data[0])!
            print(item.avatar_small)

        }
        
    }
    
    
    func netRequest1() {
        
        let url : String = "https://httpbin.org/get"
        let parameters :Dictionary  = ["name":"Hoolink","age":"18"]
        HLNetWorking.shareInstance.requestNetWork(netWorkType: .NetWorkTypeGET, requqestUrl: url, parameters:["name":"Hoolink"] ) { (response) in
            guard let  resultDic = response as? [String:NSObject] else{return}
              print(resultDic)
        }
    }
    
}

